home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / MPW_TOOL / TOOLS / TOOLS_WI / ICON_8 / ICONX_FO / RDEFAULT.C < prev    next >
Text File  |  1990-03-02  |  2KB  |  113 lines

  1. /*
  2.  * File: rdefault.c
  3.  *  Contents: defcset, deffile, defint, defshort, defstr
  4.  */
  5.  
  6. #include "::h:config.h"
  7. #include "::h:rt.h"
  8. #include "rproto.h"
  9.  
  10. /*
  11.  * defcset(dp,cp,buf,def) - if dp is null, default to def;
  12.  *  otherwise, convert to cset or die trying.
  13.  */
  14.  
  15. int defcset(dp, cp, buf, def)
  16. dptr dp;
  17. int **cp;
  18. int *buf, *def;
  19.    {
  20.    if (ChkNull(*dp)) {
  21.       *cp = def;
  22.       return Defaulted;
  23.       }
  24.    if (cvcset(dp, cp, buf) == CvtFail) 
  25.       RetError(104, *dp);
  26.    return Success;
  27.    }
  28.  
  29. /*
  30.  * deffile - if dp is null, default to def; otherwise, make sure it's a file.
  31.  */
  32.  
  33. int deffile(dp, def)
  34. dptr dp, def;
  35.    {
  36.    if (ChkNull(*dp)) {
  37.       *dp = *def;
  38.       return Defaulted;
  39.       }
  40.    if (dp->dword != D_File)
  41.       RetError(105, *dp);
  42.    return Success;
  43.    }
  44.  
  45. /*
  46.  * defint - if dp is null, default to def; otherwise, convert to integer.
  47.  *  Note that *lp gets the value.
  48.  */
  49.  
  50. int defint(dp, lp, def)
  51. dptr dp;
  52. long *lp;
  53. word def;
  54.    {
  55.    if (ChkNull(*dp)) {
  56.       *lp = (long)def;
  57.       return Defaulted;
  58.       }
  59.    if (cvint(dp) == CvtFail)
  60.       RetError(101, *dp);
  61.    *lp = IntVal(*dp);
  62.    return Success;
  63.    }
  64.  
  65. /*
  66.  * defshort - if dp is null, default to def; otherwise, convert to short
  67.  *  integer.  The result is an integer value in *dp.
  68.  */
  69.  
  70. int defshort(dp, def)
  71. dptr dp;
  72. int def;
  73.    {
  74.    if (ChkNull(*dp)) {
  75.       MakeInt((int)def, dp);
  76.       return Defaulted;
  77.       }
  78.    switch (cvint(dp)) {
  79.  
  80.       case T_Integer:
  81.      return Success;
  82.  
  83.       default:
  84.      RetError(101, *dp);
  85.       }
  86.    }
  87.  
  88. /*
  89.  * defstr - if dp is null, default to def; otherwise, convert to string.
  90.  *  *dp gets a descriptor for the resulting string.  buf is used as
  91.  *  a scratch buffer for the conversion (if necessary).
  92.  */
  93.  
  94. int defstr(dp, buf, def)
  95. dptr dp;
  96. char *buf;
  97. dptr def;
  98.    {
  99.    int retcode;
  100.  
  101.    if (ChkNull(*dp)) {
  102.       *dp = *def;
  103.       return Defaulted;
  104.       }
  105.  
  106.    retcode = cvstr(dp, buf);
  107.    if (retcode == CvtFail) {
  108.       RetError(103, *dp);
  109.       }
  110.    else
  111.       return retcode;
  112.    }
  113.